﻿using System;

namespace TheWorldLibrary
{
    public class Modifier
    {
        #region Fields and Properties

        private string modifying;
        private int amount;
        private int duration;
        private TimeSpan timeLeft;

        public string Modifying
        {
            get { return modifying; }
            set { modifying = value; }
        }

        public int Amount
        {
            get { return amount; }
            set { amount = value; }
        }

        public int Duration
        {
            get { return duration; }
            set { duration = value; }
        }

        public TimeSpan TimeLeft
        {
            get { return timeLeft; }
            set { timeLeft = value; }
        }

        #endregion

        #region Constructor

        public Modifier(string modifying, int amount)
        {
            Modifying = modifying;
            Amount = amount;
            Duration = -1;
            TimeLeft = TimeSpan.Zero;
        }

        public Modifier(string modifying, int amount, int duration)
        {
            Modifying = modifying;
            Amount = amount;
            Duration = duration;
            TimeLeft = TimeSpan.FromSeconds(duration);
        }

        #endregion

        #region Methods

        public void Update(TimeSpan elaspedTime)
        {
            if (Duration == -1)
            {
                return;
            }

            timeLeft -= elaspedTime;
            if (TimeLeft.TotalMilliseconds < 0)
            {
                TimeLeft = TimeSpan.Zero;
                Amount = 0;
            }
        }

        #endregion
    }
}
